<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::dropIfExists('scm_users');
        Schema::create('scm_users', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('主键自动增长');
            $table->string('hash_id', 191)->index()->nullable()->comment('哈希ID');
            $table->string('login_name', 191)->index()->nullable()->comment('用户名');
            $table->string('password', 191)->index()->nullable()->comment('用户名');
            $table->string('real_name', 191)->index()->nullable()->comment('姓名');
            $table->string('nick_name', 191)->index()->nullable()->comment('昵称');
            $table->string('avatar', 255)->nullable()->comment('头像');
            $table->unsignedInteger('gender')->default(2)->comment('性别');
            $table->date('birthday')->nullable()->comment('生日');
            $table->timestamp('register_time')->useCurrent()->comment('注册时间');
            $table->string('register_ip', 64)->nullable()->comment('注册IP');
            $table->string('register_ipv4', 64)->nullable()->comment('注册IPV4');
            $table->string('register_ipv6', 128)->nullable()->comment('注册IPV6');
            $table->unsignedInteger('register_source')->default(0)->comment('注册来源');
            $table->unsignedInteger('status')->default(1)->comment('状态');
            $table->text('extra_data')->nullable()->comment('扩展数据，格式为json');
            $table->timestamps();
            $table->softDeletes();
            $table->engine = 'InnoDB';
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_unicode_ci';
        });
        DB::statement("ALTER TABLE scm_users comment 'SCM 用户表';");

        Schema::dropIfExists('scm_user_binds');
        Schema::create('scm_user_binds', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('主键自动增长');
            $table->bigInteger('user_id')->nullable()->default(0)->comment('用户ID');
            $table->unsignedInteger('bind_type')->nullable()->default(0)->comment('绑定类型');
            $table->string('bind_id', 191)->index()->nullable()->default(0)->comment('绑定ID');
            $table->text('bind_data')->fulltext()->nullable()->comment('绑定数据，格式为json');
            $table->unsignedInteger('status')->default(1)->comment('状态');
            $table->text('extra_data')->nullable()->comment('扩展数据，格式为json');
            $table->timestamps();
            $table->softDeletes();
            $table->engine = 'InnoDB';
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_unicode_ci';
        });
        DB::statement("ALTER TABLE scm_user_binds comment 'SCM 用户绑定表';");


        Schema::dropIfExists('scm_owners');
        Schema::create('scm_owners', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('主键自动增长');
            $table->bigInteger('org_id')->nullable()->default(0)->comment('组织ID');
            $table->bigInteger('user_id')->nullable()->default(0)->comment('用户ID');
            $table->text('approval_logs')->nullable()->comment('审核日志，格式为json');
            $table->unsignedInteger('approval_status')->default(0)->comment('审核状态');
            $table->unsignedInteger('status')->default(1)->comment('状态');
            $table->text('extra_data')->nullable()->comment('扩展数据，格式为json');
            $table->timestamps();
            $table->softDeletes();
            $table->engine = 'InnoDB';
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_unicode_ci';
        });
        DB::statement("ALTER TABLE scm_owners comment 'SCM 业主表';");


        Schema::dropIfExists('scm_vehicles');
        Schema::create('scm_vehicles', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('主键自动增长');
            $table->string('brand', 50)->nullable()->comment('品牌');
            $table->string('model', 100)->nullable()->comment('型号');
            $table->string('license_plate', 20)->nullable()->comment('车牌号码');
            $table->string('color', 20)->nullable()->comment('颜色');
            $table->string('vin', 20)->nullable()->comment('车架号');
            $table->string('engine_number', 20)->nullable()->comment('发动机号');
            $table->date('inspection_due_date')->nullable()->comment('车辆年检到期日期');
            $table->date('insurance_due_date')->nullable()->comment('车辆保险到期日期');
            $table->bigInteger('owner_id')->nullable()->default(0)->comment('业主ID');
            $table->unsignedInteger('status')->default(1)->comment('状态');
            $table->text('extra_data')->nullable()->comment('扩展数据，格式为json');
            $table->timestamps();
            $table->softDeletes();
            $table->engine = 'InnoDB';
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_unicode_ci';
        });
        DB::statement("ALTER TABLE scm_vehicles comment 'SCM 用户车辆表';");

        Schema::dropIfExists('scm_parking_permits');
        Schema::create('scm_parking_permits', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('主键自动增长');
            $table->bigInteger('org_id')->nullable()->default(0)->comment('组织ID');
            $table->bigInteger('owner_id')->nullable()->default(0)->comment('业主ID');
            $table->string('remark', 500)->nullable()->comment('备注');
            $table->unsignedInteger('status')->default(1)->comment('状态');
            $table->text('extra_data')->nullable()->comment('扩展数据，格式为json');
            $table->timestamps();
            $table->softDeletes();
            $table->engine = 'InnoDB';
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_unicode_ci';
        });
        DB::statement("ALTER TABLE scm_parking_permits comment 'SCM 停车授权表';");

        Schema::dropIfExists('scm_parking_permit_vehicles');
        Schema::create('scm_parking_permit_vehicles', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('主键自动增长');
            $table->bigInteger('parking_permit_id')->nullable()->default(0)->comment('停车授权ID');
            $table->bigInteger('vehicle_id')->nullable()->default(0)->comment('车辆ID');
            $table->unsignedInteger('status')->default(1)->comment('状态');
            $table->text('extra_data')->nullable()->comment('扩展数据，格式为json');
            $table->timestamps();
            $table->softDeletes();
            $table->engine = 'InnoDB';
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_unicode_ci';
        });
        DB::statement("ALTER TABLE scm_parking_permit_vehicles comment 'SCM 停车授权车辆表';");

        Schema::dropIfExists('scm_parking_permit_vehicle_approvals');
        Schema::create('scm_parking_permit_vehicle_approvals', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('主键自动增长');
            $table->bigInteger('parking_permit_vehicle_id')->nullable()->default(0)->comment('停车授权车辆ID');
            $table->string('remark', 500)->nullable()->comment('备注');
            $table->text('approval_logs')->nullable()->comment('审核日志，格式为json');
            $table->unsignedInteger('status')->default(1)->comment('状态');
            $table->text('extra_data')->nullable()->comment('扩展数据，格式为json');
            $table->timestamps();
            $table->softDeletes();
            $table->engine = 'InnoDB';
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_unicode_ci';
        });
        DB::statement("ALTER TABLE scm_parking_permit_vehicle_approvals comment 'SCM 停车授权审核表';");


    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
};
